home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / gnustuff / tos / util / utlsrc37.zoo / size68.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-30  |  2.9 KB  |  140 lines

  1. /*                             -*- Mode: Elec-C -*- 
  2.  * size68.c -- report segment sizes take from program header
  3.  * 
  4.  * Author          : probably J.R.Bammi
  5.  * Created On      : some years ago
  6.  * Last Modified By: Frank Ridderbusch
  7.  * Last Modified On: Wed Apr 14 21:22:02 1993
  8.  * Update Count    : 6
  9.  * Status          : Unknown, Use with caution!
  10.  */
  11.  
  12. /* HISTORY 
  13.  * 14-Apr-1993        Frank Ridderbusch    
  14.  *    Deleted the prgflags structure in this file, since it is in
  15.  *    <st-out.h>. Added code to report status on all prgflags defined
  16.  *    upto now.
  17.  */
  18.  
  19. #include <stdio.h>
  20. #include <st-out.h>
  21.  
  22. /*
  23.  * ldflgs - stolen from MiNT mem.h
  24.  */
  25.  
  26. #define    F_PROTMODE    0xf0        /* protection mode bits */
  27. #define F_PROT_P    0x00        /* no read or write */
  28. #define F_PROT_G    0x10        /* any access OK */
  29. #define F_PROT_S    0x20        /* any super access OK */
  30. #define F_PROT_PR    0x30        /* any read OK, no write */
  31.  
  32. extern FILE *fopen();
  33.  
  34. main(argc, argv)
  35. int argc;
  36. char **argv;
  37. {
  38.     while(--argc > 0)
  39.         showfile(*++argv);
  40.     return 0;
  41. }
  42.  
  43. showfile(name)
  44. char *name;
  45. {
  46.     register FILE *fp;
  47.     struct aexec h;
  48.     
  49.     if((fp = fopen(name, "rb")) == (FILE *)NULL)
  50.     {
  51.         perror(name);
  52.         exit(1);
  53.     }
  54. # ifndef WORD_ALIGNED
  55.     if(fread(&h, sizeof(struct aexec), 1, fp) != 1)
  56.     {
  57.         perror(name);
  58.         exit(2);
  59.     }
  60. #else
  61.     aligned_read(&h, fp);
  62. #endif
  63.     fclose(fp);
  64.     
  65.     if(h.a_magic != CMAGIC)
  66.     {
  67.         fprintf(stderr,"Bad Magic #: 0X%x\n", h.a_magic);
  68.         exit(3);
  69.     }
  70.     printf("%s:\n\ttext size\t%ld\n\tdata size\t%ld\n\tbss size\t%ld\
  71. \n\tsymbol size\t%ld\n\tFile %s relocatable.\n\
  72. \t%s cleared on startup.\n", name, h.a_text,
  73.      h.a_data, h.a_bss, h.a_syms,
  74.     (h.a_isreloc == ISRELOCINFO) ? "is" : "is not",
  75.     (h.a_AZero2 & F_FASTLOAD) ? "Only BSS" : "BSS and high mem");
  76.     printf("\tFile is loaded into %s\n", 
  77.         (h.a_AZero2 & F_ALTLOAD) ? "alternate ram" : "ST ram");
  78.     printf("\t and allocates memory from %s.\n", 
  79.         (h.a_AZero2 & F_ALTALLOC) ? "alternate ram" : "ST ram");
  80.     printf("\tFile runs with `%s' memory protection (under MultiTOS).\n", 
  81.         (((h.a_AZero2 & F_PROTMODE) == F_PROT_PR) ? "readable" : 
  82.     (((h.a_AZero2 & F_PROTMODE) == F_PROT_S)  ? "super" :
  83.     (((h.a_AZero2 & F_PROTMODE) == F_PROT_G)  ? "global" : "private"))));
  84. }
  85.  
  86. # ifdef WORD_ALIGNED
  87. void ckfread(buf, siz, n, fp)
  88. char *buf;
  89. int siz, n;
  90. FILE *fp;
  91. {
  92.     if(fread(buf, siz, n, fp) != n)
  93.     {
  94.         perror("reading");
  95.         exit(3);
  96.     }
  97. }
  98.  
  99. aligned_read(h, fp)
  100. struct aexec *h;
  101. FILE *fp;
  102. {
  103.     short i;
  104.     long j;
  105.  
  106.     ckfread(&i, 2, 1, fp);
  107.     h->a_magic = i;
  108.     ckfread(&j, 4, 1, fp);
  109.     h->a_text = j;
  110.     ckfread(&j, 4, 1, fp);
  111.     h->a_data = j;
  112.     ckfread(&j, 4, 1, fp);
  113.     h->a_bss = j;
  114.     ckfread(&j, 4, 1, fp);
  115.     h->a_syms = j;
  116.     ckfread(&j, 4, 1, fp);
  117.     h->a_AZero1 = j;
  118.     ckfread(&j, 4, 1, fp);
  119.     h->a_AZero2 = j;
  120.     ckfread(&i, 2, 1, fp);
  121.     h->a_isreloc = i;
  122. }
  123. #endif
  124.  
  125. #ifdef CROSSHPUX
  126. char *xmalloc(n)
  127. unsigned n;
  128. {
  129.     extern char *malloc();
  130.     char *ret = malloc(n);
  131.     
  132.     if(!ret)
  133.     {
  134.         fprintf(stderr,"Out of memory!\n");
  135.         exit(1);
  136.     }
  137.     return ret;
  138. }
  139. #endif
  140.